﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VINETLIFE.BL;
using VINETLIFE.DO;

namespace VINETLIFE.AdminCP
{
    public partial class ListSlide : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                gvSlide.DataSource = new SlideBL().SelectAll();
                gvSlide.DataBind();
            }
        }
        public string BindCategory(object e)
        {
            if (e == null)
            {
                return "";
            }
            else
            {
                string returnX = "";
                int categoryId = -1;
                try
                {
                    categoryId = int.Parse(e.ToString());
                    if (categoryId == 0)
                    {
                        returnX = "Slie trang Business Partner";
                    }
                    else if (categoryId == 1)
                    {
                        returnX = "Slide trang chủ";
                    }
                    else if (categoryId == 2)
                    {
                        returnX = "Slide Đối tác(chân trang)";
                    }
                }
                catch
                {
                    returnX = "";
                }
                return returnX;
            }
        }
        protected void gvSlide_SelectedIndexChanged(object sender, EventArgs e)
        {
            int SlideID = int.Parse(gvSlide.DataKeys[gvSlide.SelectedIndex].Value.ToString());
            Response.Redirect("Slide.aspx?SlideID=" + SlideID.ToString());
        }

        protected void cboCategory_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cboCategory.SelectedIndex <= 0)
            {
                gvSlide.DataSource = new SlideBL().SelectAll();
                gvSlide.DataBind();
            }
            else
            {
                Functions.GvDatabinder(gvSlide, new SlideBL().SelectByCategoryID(int.Parse(cboCategory.SelectedValue)));
            }
        }


        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect("Slide.aspx");
        }

        protected void gvSlide_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            new SlideBL().Delete(new SlideDO { SlideID = Convert.ToInt32(gvSlide.DataKeys[e.RowIndex].Value) });
            Functions.Alert("Xóa thành công", "ListSlide.aspx");
        }
    }
}